package exam.bank.service.impl;

import java.util.List;
import java.util.Map;

import exam.bank.dao.BankDao;
import exam.bank.dao.impl.BankDaoImpl;
import exam.bank.entity.BankEntity;
import exam.bank.service.BankService;

/**
*@author jzh
*@创建时间 2017年6月17日上午10:15:10
*类说明：
*/
public class BankServiceImpl implements BankService {
	
	BankDao bankDao=new BankDaoImpl();
	
	@Override
	public void addBank(String bankName, String bankPhone, String bankAddress,Map<String,Object>mp) {
		BankEntity bankEntity=new BankEntity();
		bankEntity.setBankName(bankName);
		bankEntity.setBankPhone(bankPhone);
		bankEntity.setBankAddress(bankAddress);
		
		try {
			int counter = bankDao.addBank(bankEntity);
			mp.put("bankEntity", bankEntity);
			mp.put("result", "增加成功");
		} catch (Exception e) {
			mp.put("result", "增加失败");
		}
	}

	@Override
	public void findAllBank(String cur,String ps,Map<String, Object> mp) {
		
		// 非空检查，并赋默认值
		if (null == cur || "".equals(cur)) {
			cur = "1";
		}
		int curpage = Integer.parseInt(cur);
		if (null == ps || "".equals(ps)) {
			ps = "3";
		}
		int pageSize = Integer.parseInt(ps);
				
		try {
			List<BankEntity> bankLists = bankDao.findAllBank();
			mp.put("bankLists", bankLists);
			mp.put("result", "查找成功");
		} catch (Exception e) {
			mp.put("result", "查找失败");
		}
		
	}

	@Override
	public void findBankById(String upStr, Map<String, Object> mp) {
		Integer upId=Integer.parseInt(upStr);
		try {
			BankEntity bankEntity = bankDao.findBankById(upId);
			mp.put("bankEntity", bankEntity);
			mp.put("result", "成功");
		} catch (Exception e) {
			mp.put("result", "失败 ");
		}
	}

	@Override
	public void updateBank(String bankId, String bankName, String bankPhone, String bankAddress,
			Map<String, Object> mp) {
		BankEntity bankEntity=new BankEntity();
		bankEntity.setBankName(bankName);
		bankEntity.setBankPhone(bankPhone);
		bankEntity.setBankAddress(bankAddress);
		Integer upId=Integer.parseInt(bankId);
		bankEntity.setId(upId);
		
		try {
			bankDao.updateBank(bankEntity);
			mp.put("result", "修改成功");
		} catch (Exception e) {
			mp.put("result", "修改失败 ");
		}
	}

	@Override
	public void deleteBank(String id, Map<String, Object> mp) {
		Integer delId=Integer.parseInt(id);
		try {
			bankDao.deleteBank(delId);
			mp.put("result", "删除成功");
		} catch (Exception e) {
			mp.put("result", "删除失败 ");
		}
	}

}
